package com.acme.benchmarks;

import com.acme.HashMapFactory;

import java.util.Map;

/**
 * Created by Type on 28.11.13.
 */
public abstract class Benchmark {

    private boolean outputEnabled;

    private int iterations;
    private int growFactor;

    public static final int[] KEY_POINTS = {1000,10000,100000,1000000,10000000};

    protected String accString = "";

    private HashMapFactory factory;

    public Benchmark(int iterations, int growFactor, HashMapFactory factory){
        this.iterations = iterations;
        this.growFactor = growFactor;
        this.factory = factory;
    }



    public void  heat(){
        accString = "";
        outputEnabled = false;
        for (int i = 1; i <= iterations/2; i++) {
            runIteration(growFactor/2 * i);
        }
        System.out.println("acc: " + accString);
    }

    public void run(){
        accString = "";
        outputEnabled = true;
        for (int i = 1; i <= iterations; i++) {
            runIteration(growFactor * i);
        }
        for (int KEY_POINT : KEY_POINTS) {
            runIteration(KEY_POINT);
        }
        System.out.println("acc: "+accString);
    }

    protected Map<Integer, Integer> generateMap(int size){
        return factory.generateMap(size);
    }

    protected abstract void runIteration(int iterationSize);


    protected void log(String s) {
        if(outputEnabled){
            System.out.println(s);
        }
    }

    protected void err(String s){
        if(outputEnabled){
            System.err.println(s);
        }
    }

}
